package com.example.work4.data

import android.content.Context
import androidx.room.Database

import androidx.room.RoomDatabase
import androidx.room.Room




@Database(entities = [Record::class], version = 1, exportSchema = false)
abstract class RecordDataBase : RoomDatabase() {
    abstract fun recordDao():RecordDao

    companion object {
        @Volatile
        private var INSTANCE: RecordDataBase? = null

        fun getDatabase(context: Context,dbName:String): RecordDataBase{

            val tempInstance = INSTANCE
            if(tempInstance != null) { return tempInstance }
            synchronized(this){
                val instance = Room.databaseBuilder(context.applicationContext,
                    RecordDataBase::class.java, dbName).build()
                INSTANCE = instance
                return instance
            }
        }
    }
}